#include <iostream>
#include <cstring>
using namespace std;

const int N = 110;

int n, m;                   //组数和背包容量
int s[N], v[N][N], w[N][N]; //组内物品数和物品属性
int f[N][N];                //状态表示数组

int main()
{
    // freopen("cin.txt", "r", stdin);
    memset(f, 0, sizeof f);
    cin >> n >> m;
    for (int i = 1; i <= n; ++i)
    {
        cin >> s[i];
        for (int j = 1; j <= s[i]; ++j)
            cin >> v[i][j] >> w[i][j];
    } //输入必要信息
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= m; ++j)
        {
            f[i][j] = f[i - 1][j];
            for (int k = 1; k <= s[i]; ++k)
                if (j >= v[i][k])                                            //只要装得下
                    f[i][j] = max(f[i][j], f[i - 1][j - v[i][k]] + w[i][k]); //那就一较高下
        }
    cout << f[n][m];
    return 0;
}